﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace Platform.ObjectModel.Collections
{
	/// <summary>
	/// 
	/// </summary>
	/// <typeparam name="TFlag"></typeparam>
	public class FlagCollection<TFlag>
		where TFlag : IConvertible
	{
		private long flags = 0;

		#region [ .ctor ]

		/// <summary>
		/// 
		/// </summary>
		public FlagCollection()
			: this( 0 )
		{ }

		/// <summary>
		/// 
		/// </summary>
		/// <param name="flags"></param>
		public FlagCollection( long flags )
		{
			this.flags = flags;
		}

		#endregion

		/// <summary>
		/// 
		/// </summary>
		public long Data
		{
			get { return this.flags; }
			set { this.flags = value; }
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="flag"></param>
		public void Set( TFlag flag )
		{
			long mask = flag.ToInt64( CultureInfo.InvariantCulture );
			this.flags |= mask;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="flag"></param>
		public void Unset( TFlag flag )
		{
			long mask = flag.ToInt64( CultureInfo.InvariantCulture );
			this.flags &= ~mask;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="flag"></param>
		/// <returns></returns>
		public bool Is( TFlag flag )
		{
			long mask = flag.ToInt64( CultureInfo.InvariantCulture );
			return ( this.flags & mask ) > 0;
		}
	}
}
